package cn.oms.oms.controller;

import cn.oms.oms.entity.Bill;
import cn.oms.oms.service.IBillService;
import cn.oms.oms.vo.BillVo;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author AllenChen曾晨
 * @since 2022-04-29
 */
@RestController
@RequestMapping("/oms/bill")
@Slf4j
public class BillController {

    @Autowired
    public IBillService billService;

    /**
     * 根据查询条件查询账单列表
     * @param billVo
     * @return
     */
    @PostMapping("/selectBillList")
    public PageInfo<Bill> selectBillList(BillVo billVo){
        if(billVo.getPageNum()==null||billVo.getPageNum()==0){
            billVo.setPageNum(1);
        }
        if(billVo.getPageSize()==null||billVo.getPageSize()==0){
            billVo.setPageSize(10);
        }
        log.debug("接收到信息:{}",billVo);
        PageInfo<Bill> pageInfo = billService.selectBillList(billVo);
        return pageInfo;
    }
    /**
     * 新增账单
     * @param billVo
     * @return
     */
    @PostMapping("/addBill")
    public String addBill(BillVo billVo){
        log.debug("接收到信息:{}",billVo);
        String res = billService.addBill(billVo);
        return res;
    }
    /**
     * 修改账单
     * @param billVo
     * @return
     */
    @PostMapping("/updateBill")
    public String updateBill(BillVo billVo){
        log.debug("接收到信息:{}",billVo);
        String res = billService.updateBill(billVo);
        return res;
    }
    /**
     * 删除账单
     * @param id
     * @return
     */
    @PostMapping("/deleteBill/{id}")
    public String deleteBill(@PathVariable Integer id){
        log.debug("接收到信息:{}",id);
        String res = billService.deleteBill(id);
        return res;
    }


}
